<template>
    <div class="Preson">
      <h2>姓名：{{ name }}</h2>
      <h2>年龄：{{ age }},{{ nianli }}</h2>
      <button @click="changeName">修改名字</button>
      <button @click="changeAge">修改年龄</button>
    </div>
</template>

<script lang="ts" setup>
import { reactive, ref ,toRef,toRefs} from 'vue'
let person = reactive({
    name: '张三',
    age:20
})
// toRefs会把preson对象里所有的key，value解构出来，变成响应式数据
let { name, age } = toRefs(person)
// toRef只是把preson对象里的key拿出来，变成响应式数据
let nianli = toRef(person, 'age')

function changeName() {
    name.value += '~'
    console.log(name);
    
}
function changeAge() {
    age.value += 1
    console.log(age);
    
}
</script>

<style scoped>
.Preson {
    background-color: #ddd;
    box-shadow: 0 0 10px;
    border-radius: 10px;
    padding: 20px;
}

button {
    margin: 0 10px;
}
</style>